package com.renjianbo.project.module.flowable.utils;



import com.renjianbo.project.module.flowable.common.constant.TaskConstants;
import com.renjianbo.project.module.flowable.common.model.BladeUser;
import com.renjianbo.project.module.flowable.common.model.SecureUtil;
import com.renjianbo.project.module.flowable.common.util.Func;
import com.renjianbo.project.module.flowable.common.util.ObjectUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 工作流任务工具类
 *
 * @author konbai
 * @createTime 2022/4/24 12:42
 */
public class TaskUtils {

    public static String getUserId() {
        return String.valueOf(SecureUtil.getUserId());
    }

    /**
     * 获取用户组信息
     *
     * @return candidateGroup
     */
    public static List<String> getCandidateGroup() {
        List<String> list = new ArrayList<>();
        BladeUser user = SecureUtil.getUser();
        if (!Func.isNull(user)) {
            List<String> roleIds = Func.toStrList(user.getRoleId());
            if (ObjectUtil.isNotEmpty(user.getRoleId())) {
                roleIds.forEach(role -> list.add(TaskConstants.ROLE_GROUP_PREFIX + role));
            }
            if (!Func.isNull(user.getDeptId())) {
                list.add(TaskConstants.DEPT_GROUP_PREFIX + user.getDeptId());
            }
        }
        return list;
    }
}
